/**   
 * @Project: SpringInAction 
 * @Title: TestAspect.java 
 * @Package net.weamor.spring.action.monitor.aop 
 * @Description: TODO 
 * @author weamor
 * @date 2015年11月9日 下午3:42:22 
 * @version V1.0   
 */
package net.weamor.spring.action.monitor.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;

/** 
 * @ClassName TestAspect  
 * @Description TODO 
 * @author weamor
 * @date 2015年11月9日  
 *   
 */
public class TestAspect {
	public void doAfter(JoinPoint jp) {
		System.out.println("log Ending method: "
				+ jp.getTarget().getClass().getName() + "."
				+ jp.getSignature().getName());
	}

	public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
		long time = System.currentTimeMillis();
		Object retVal = pjp.proceed();
		time = System.currentTimeMillis() - time;
		
		//采用环绕通知
		
		System.out.println("around method :"+pjp.getSignature().getName());
		
		System.out.println("process time: " + time + " ms");
		return retVal;
	}

	public void doBefore(JoinPoint jp) {
		System.out.println("log Begining method: "
				+ jp.getTarget().getClass().getName() + "."
				+ jp.getSignature().getName());
	}

	public void doThrowing(JoinPoint jp, Throwable ex) {
		System.out.println("method " + jp.getTarget().getClass().getName()
				+ "." + jp.getSignature().getName() + " throw exception");
		System.out.println(ex.getMessage());
	}

	private void sendEx(String ex) {
		// TODO 发送短信或邮件提醒

	}
}
